package cn.itsource.pethome.basic.controller;

import cn.itsource.pethome.basic.service.IVerificationCodeService;
import cn.itsource.pethome.basic.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verification")
public class VerificationCodeController {
    @Autowired
    private IVerificationCodeService verificationCodeService;

    @PostMapping("/sendRegisterMobileCode")
    public Result sendRegisterMobileCode(@RequestBody Map<String,String> param){
        try {
            //获取前端传入的电话
            String phone = param.get("phone");
            //发送验证码
            verificationCodeService.sendRegisterMobileCode(phone);
            return new Result();
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,e.getMessage());
        }
    }

    @PostMapping("/sendBinderMobileCode")
    public Result sendBinderMobileCode(@RequestBody Map<String,String> param){
        try {
            //获取前端传入的电话
            String phone = param.get("phone");
            //发送验证码
            verificationCodeService.sendBinderMobileCode(phone);
            return new Result();
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,e.getMessage());
        }
    }
}
